/**
 * Copyright (C), 2015, 上海赛可电子商务有限公司
 * Author:   张卫明
 * Date:     2015-4-28
 * lever:    page
 * Description: 首页js
 */

;(function($,window) {
	var imgEle = $('.minimg-box'),
		closeImg = $('.close-image-detail');
	
	myCommentList = {
			
		init:function(){
			
			//查看大图 
			this.showBigImg();
			
			//分页
			this.goPage();
			
			//多行省略号
			this.figCation();
			
		},
		showBigImg:function(){
			imgEle.on('click',function(){
				var _this = $(this),
					_num =  _this.index(),
					_parent = _this.parents('.comment-info'),
					_imgDetail = _parent.find('.comment-info-image-detail'),
					_imgEle = _parent.find('.minimg-box'),
					_imgBig = _parent.find('.img-big');
				
				if(_this.hasClass('minimg-sel')){
					return false;
				};
				
				_imgDetail.show();
				
				_imgEle.removeClass('minimg-sel');
				_imgBig.hide();
				
				_this.addClass('minimg-sel');
				_imgBig.eq(_num).show();
				
			});
			
			closeImg.on('click',function(){
				var _this = $(this),
				_parent = _this.parents('.comment-info'),
				_imgDetail = _parent.find('.comment-info-image-detail'),
				_imgEle = _parent.find('.minimg-box'),
				_imgBig = _parent.find('.img-big');
				
				_imgEle.removeClass('minimg-sel');
				_imgBig.hide();
				_imgDetail.hide();
			});
		},
		//分页
		goPage: function(currentPageNo){
			/*$.ajax({
				url:"/product/Evaluation.htm",
				type:'POST',
				data:{
					currentPage:currentPageNo,
					velModelId:velModelId
				},
				success:function(response){
					$('#evaluation_content').html(response);
				},
				error:function(errorMessage){

				}
			});*/
			
			//多行省略号
			this.figCation();
		},
		figCation:function(){
			
			$(".figcaption").each(function(i){
			    var divH = $(this).height();
			    var $p = $(this).children().eq(0);
			    while ($p.outerHeight() > divH) {
			        $p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
			    };
			});
			
		}
	};
	
	myCommentList.init();
	
})(jQuery,window);

